package org.thingsboard.server.dao.sql.tenantip;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.jpa.domain.JpaSort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.data.repository.CrudRepository;
import org.springframework.stereotype.Component;
import org.thingsboard.server.dao.model.sql.CamerasInfo;
import org.thingsboard.server.common.data.TenantIp;
import org.thingsboard.server.dao.model.sql.TenantIpEntity;
import org.thingsboard.server.dao.model.sql.VideoEntity;
import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
import org.thingsboard.server.dao.tenantIp.TenantIpDao;

import java.util.*;


@Component
public class JpaTenantIpDao
        implements TenantIpDao {

    @Autowired
    private TenantIpRepository tenantIpRepository;

    protected Class<TenantIpEntity> getEntityClass() {
        return null;
    }


    @Override
    public String getIpByDeviceName(String deviceName) {
        return tenantIpRepository.getIpByDeviceName(deviceName);
    }

    @Override
    public String getIpByLoginUser(String tenantName) {
        return tenantIpRepository.getIpByLoginUser(tenantName);
    }

    @Override
    public List<CamerasInfo> getCameras(String tenantName) {
        return tenantIpRepository.getCameras(tenantName);
    }

    @Override
    public Map getCamerasIdByDeviceName(String device) {
        return tenantIpRepository.getCamerasIdByDeviceName(device);
    }

    @Override
    public List<TenantIp> getIpAndPwd() {
        ArrayList<TenantIp> list = new ArrayList<>();
        Iterable<TenantIpEntity> all = tenantIpRepository.findAll();
        all.forEach(iplist -> {
            list.add(new TenantIp(iplist.getTenantId(), iplist.getIp()));
        });
        return list;
    }
}
